<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>watchEffect与compute有什么区别？</title>
</head>

<body>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>


    <div id="Application">
        {{sayHello}}
    </div>
    <script>
        const App = Vue.createApp({
            setup() {
                const age = Vue.ref(0);
                Vue.watchEffect(() => {
                    //当变量a变化时，即执行当前函数
                    console.log("变量age变化了")
                    console.log(age.value)
                })
                setTimeout(() => { age.value = 20 }, 1000)

                const name = Vue.ref('小王');
                const sayHello = Vue.computed(() => {
                    console.log('年龄：', age.value);
                    return "我是" + name.value + "，" + age.value + "岁"
                })
                return {
                    sayHello,
                    name,
                    age
                }
            }
        })
        App.mount("#Application")
    </script>
</body>

</html>